package com.wwp.tbshop.presenter;

import android.util.Log;

import com.wwp.tbshop.activity.category.GoodsListActivity;
import com.wwp.tbshop.model.bean.GoodsListBean;

import retrofit2.Call;

/**
 * Created by 楠GG on 2017/6/18.
 */

public class GoodsListPresenter extends BasePresenter<GoodsListBean> {
    private static final String TAG = "GoodsListPresenter";
    private GoodsListActivity mGoodsListActivity;

    public GoodsListPresenter(GoodsListActivity goodsListActivity) {
        mGoodsListActivity = goodsListActivity;
    }

    /**
     * @param page  第几页
     * @param pageNum   每页个数
     * @param cId   分类id
     * @param orderBy   排序
     * @param filter    筛选
     */
    public void loadGoodsList(int page, int pageNum, int cId, String orderBy, String filter) {
        //mApiService是在父类中的
        Call<GoodsListBean> goodsListCall = mApiService.getGoodsList(page, pageNum, cId, orderBy, filter);
        //mCallback 是在父类中的
        goodsListCall.enqueue(mCallback);
    }

    @Override
    protected void onServerBug(int code) {
        mGoodsListActivity.onServerBug(code);
    }

    @Override
    protected void onConnectError(String message) {
        mGoodsListActivity.onError(message);
    }

    @Override
    protected void onSuccess(GoodsListBean goodsListBean) {
        if(goodsListBean == null) {
            Log.d(TAG, "onSuccess: 数据为空");
            return;
        }
        Log.d(TAG, "onSuccess: " + goodsListBean.getResponse());
        mGoodsListActivity.onSuccess(goodsListBean);
    }
}
